<?php 
	defined('_JEXEC') or die('Restricted access');
	$col = 3;
	$item_count = 0;
	$span = 12 / $col;
	require_once (JPATH_COMPONENT.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'util.php');
	$input = JFactory::getApplication()->input;
	$catid = $input->get("catid");
	$location_id = $input->get("location");
	$location_alias = $input->get("location_alias");
	$catid = $input->get("catid");
	$cat_alias = $input->get("cat_alias");
	if(empty($catid))
	{
		$link = "index.php?option=com_bakerys&view=bakery&location=$location_id:$location_alias&id=";
	}else 
	{
		$link = "index.php?option=com_bakerys&view=bakery&location=$location_id:$location_alias&catid=$catid:$cat_alias&id=";	
	}
	
	$doc = JFactory::getDocument();
	$doc->addScript(JUri::root(true)."/media/com_bakerys/js/storage.js");
	$doc->addScript(JUri::root(true)."/media/com_bakerys/js/bakery.js");
	JText::script("COM_BAKERYS_ITEM_ADDTOCARTJS");
	JText::script("COM_BAKERYS_ITEM_CONTINUESHOPPINGJS");
	JText::script("COM_BAKERYS_ITEM_SHOWCARTJS");
	JText::script("COM_BAKERYS_ITEM_PRODUCTNUMBERJS");
?>

<div class="browse-view">
	<?php foreach($this->items as $item): ?>
		<?php if(!empty($catid) && $item_count == 0): ?>
			<h1><?php echo $item->category_title ?></h1>
		<?php endif; ?>
		<?php $item_count++; ?>
		<?php if($item_count == 1): ?>
			<div class="row">
		<?php endif; ?>
		
		<!-- content  -->
			<div class="product span<?php echo $span ?> vertical-separator">
				<div class="spacer">
					<div class='product_container'>
					<div class="floatleft center image-product">				
						<a href="<?php echo JRoute::_($link . $item->id.':'.$item->alias) ?>" rel="vm-additional-images">
							<span class="item-image">
								<span class="border-img"></span>
								<span class="zoom-img"></span>
								<img class='browseProductImage' src="<?php echo JUri::root(true).'/'.$item->images ?>" />
							</span>
						</a>
					</div>
					
					<div class="info-product">
						<h2>
							<a href="<?php echo JRoute::_($link . $item->id.':'.$item->alias) ?>"><?php echo $item->title ?></a>
						</h2>
						<p class="product_s_desc">
							<?php echo BakeryUtil::limitString($item->introtext, 80,"...") ?>
						</p>
						<div class="product-price marginbottom12">
							<div class="PricesalesPrice" style="display : block;">
								<?php echo JText::_("COM_BAKERYS_ITEM_PRICE_VIEWLIST") ?> 
								<span class="PricesalesPrice">
									<?php if(empty($item->location_price)): ?>
										<?php echo number_format($item->price,2,",",".") ?> $
									<?php else: ?>
										<?php echo number_format($item->location_price,2,".",",") ?> $	
									<?php endif; ?>
								</span>
							</div>
						</div>
						
						<div class="btn-action clearfix">
							<div class="wrap-button">
								<a href="<?php echo JRoute::_($link . $item->id.':'.$item->alias) ?>" class="button1 product-details">
									<?php echo JText::_("COM_BAKERYS_ITEM_BTNDETAIL") ?>
								</a>
							</div>
							
							<div class="addtocart-area">
								<span class="addtocart-button">
									<input type="button" onclick="addtocart(<?php echo $item->id ?>,'<?php echo $item->title ?>',<?php echo $location_id ?>)" name="addtocart" class="addtocart-button" value="<?php echo JText::_("COM_BAKERYS_ITEM_BTNADDTOCART") ?>">
								</span>
							
								<div class="clear"></div>
							</div>
						</div>
					</div>
					</div>
				</div>
			</div>
		<!-- end content  -->
		
		<?php if($item_count % 3 == 0 && $item_count != count($this->items)): ?>
			</div>
			<div class="row">
		<?php endif; ?>
		
		<?php if($item_count == count($this->items)): ?>
			</div>
		<?php endif; ?>
	<?php endforeach; ?>
	

	<div class="pagging-sort">
		<div class="pagination clearfix">
		<?php echo $this->pagination->getPagesLinks() ?>
		</div>
	</div>
</div>

<script>
	jQuery(document).ready(function(){
		if(jQuery(".pagging-sort").find("ul.pagination").length <= 0)
		{
			jQuery(".pagging-sort").hide();
		}
	})
</script>
